from django.http import JsonResponse


def my_decorator(func):
    #自定义用户是否登陆
    def wrapper(request,*args,**kwargs):
        if request.user.is_authenticated:
            return func(request,*args,**kwargs)
        else:
            return JsonResponse({
                'errno': 4101,
                'errmsg': '未登录'
            })
    return wrapper


class LoginRequiredMixin(object):
    #定义用户是否登陆
    @classmethod
    def as_view(cls,**initkwarges):
        view=super().as_view(**initkwarges)
        return my_decorator(view)